package com.lagou.sharding.service.impl;

import com.lagou.sharding.dao.COrderDao;
import com.lagou.sharding.entity.COrder;
import com.lagou.sharding.service.COrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (COrder)表服务实现类
 *
 * @author makejava
 * @since 2020-08-18 10:58:48
 */
@Service("cOrderService")
public class COrderServiceImpl implements COrderService {
    @Resource
    private COrderDao cOrderDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public COrder queryById(Long id) {
        return this.cOrderDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<COrder> queryAllByLimit(int offset, int limit) {
        return this.cOrderDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param cOrder 实例对象
     * @return 实例对象
     */
    @Override
    public COrder insert(COrder cOrder) {
        this.cOrderDao.insert(cOrder);
        return cOrder;
    }

    /**
     * 修改数据
     *
     * @param cOrder 实例对象
     * @return 实例对象
     */
    @Override
    public COrder update(COrder cOrder) {
        this.cOrderDao.update(cOrder);
        return this.queryById(cOrder.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.cOrderDao.deleteById(id) > 0;
    }
}
